﻿using Microsoft.Xna.Framework;
using PoolGame2.Assets;

namespace PoolGame2.Physics
{
    class BallCushionCollision : Collision
    {

        public BallCushionCollision(Ball a, Cushion b, float collideTime)
        {
            this.a = a;
            this.b = b;
            this.collisionTime = collideTime;
        }

        public BallCushionCollision(Ball a, Cushion b, float collideTime, int val)
            : this(a, b, collideTime)
        {
            this.value = val;
        }

        public override void ResolveCollision(bool playSound)
        {
            Ball ball = (Ball)a;
            Cushion cush = (Cushion)b;

            Vector3 normal = Vector3.Zero;
            // this is a fix 
            if (value == 0)
            {
                normal = cush.startNormal;
            }
            else if (value == 1)
            {
                normal = cush.mainNormal;
            }
            else if (value == 2)
            {
                normal = cush.endNormal;
            }
            //if (Vector3.Dot(normal, ball.velocity) < 0) {

            ball.velocity = Vector3.Reflect(ball.velocity, normal);
            ball.velocity *= PhysicsConstants.BALL_CUSHION_ELASTICITY_COEFFICIANT;

            if (playSound)
            {
                PoolGame.audioDBManger.PlaySoundEffect(SoundEffectType.BALL_HITS_CUSHION);
            }
            //}
        }

        public override Vector3 GetCollisionPoint()
        {
            return a.getPosition();
        }
    }
}
